package my.algo.data;

/**
 * @author fengbo
 * @date 2018/8/2
 */
public class Stack<T> {

    private Node first;
    private int N;

    public boolean isEmpty() {
        return first == null;
    }

    public int size() {
        return N;
    }

    public void push(T item) {
        Node oldFirst = first;
        first = new Node();
        first.item = item;
        first.next = oldFirst;
        N++;
    }

    public T pop() {
        T item = first.item;
        first = first.next;
        N--;
        return item;
    }

    private class Node {
        T item;
        Node next;
    }
}
